#open函数
# f=open("F:/Python/word.txt","r",encoding="utf-8")
# print(type(f))

# read()方法
# print(f"读取10字节：{f.read(10)}")
# print(f"读取全部:{f.read()}")

# readlines()方法
# file=f.readlines()
# print(type(file))
# print(f"文件内容是{file}")

# readline方法
# print(f"第一行文字是{f.readline()}")
# print(f"第二行文字是{f.readline()}")
# print(f"第三行文字是{f.readline()}")

#循环读取文件
# for file in f:
#     print(file)

# 写入
# f=open("F:/Python/work.txt","r",encoding="utf-8")
# 写入一个不存在的文件
# f.write("Hello World")
# f.flush()
# print(f.read())

# 写入一个存在的文件
# f.write("hello world")
# f.close()

# 追加内容
# f=open("F:/Python/work.txt","a",encoding="UTF-8")
# f.write("\n你好世界")
# f.close()

# f=open("F:/Python/work.txt","a",encoding="utf-8")
# f.write("测试")
# f.flush()
# f.close()
#
# r=open("F:/Python/work.txt","r",encoding="utf-8")
# print(r.read())
# r.close()